home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AOL File Library: 2,801 to 2,900
/
aol-file-protocol-4400-2801-to-2900.zip
/
AOLDLs
/
C++ Files Library
/
Acere (Card Game)
/
AcereÄ.sit
/
Acereƒ
/
CardDeck.cp
< prev
next >
Wrap
Text File
|
1994-08-24
|
5KB
|
223 lines
#include "CardDeck.h"
#include "AcereApp.h"
#define kNoCard -1
static RGBColor RGBwhite;
CardDeck *theDeck;
CardDeck::CardDeck()
{
GetDateTime((unsigned long *)&qd.randSeed); // initialize randomizer when we create a new deck object
// since Generate doesn't do this, we only do it once per session
ZapOldDeck();
GenerateNewDeck();
nextCardPosition = 0;
RGBwhite.red = RGBwhite.blue = RGBwhite.green = 0xffff;
}
CardDeck::~CardDeck()
{
}
void CardDeck::GenerateNewDeck()
{
#define abs(x) (x) < 0 ? (-x) : (x)
unsigned short i = 0, tempShort;
Boolean happy;
for (i = 0; i < NumCards; i++)
theCardPositions[i] = -1;
for (i = 0; i < NumCards; i++)
{
happy = false;
do
{
tempShort = abs(Random());
tempShort = tempShort% NumCards;
if ((theCardPositions[tempShort] == -1) && (theCards[i] == -1)) // card is unassigned & so is position
{
happy = true;
theCardPositions[tempShort] = i;
theCards[i] = tempShort;
}
} while (!happy);
}
}
void CardDeck::ZapOldDeck() // after we finish a game to cleanup before generating a new one
{
short i;
for (i=0; i < NumCards; i++)
{
theCards[i] = -1;
}
}
void CardDeck::DrawCard(CardStruct *whichCard, Rect theRect)
{
Rect tempRect;
RGBColor theBackColor;
CIconHandle theIcon;
short saveFont, saveSize;
Str15 cardString;
Boolean fullCard = (theRect.bottom - theRect.top > 30);
if (whichCard->card == kNoCard)
return;
// GetCardInfo(whichCard, theCard);
GetBackColor(&theBackColor);
RGBBackColor(&RGBwhite);
if (fullCard)
{
EraseRoundRect(&theRect, 20, 20);
FrameRoundRect(&theRect, 20, 20);
}
else // we need to do PART of a rounded rectangle
{
DrawShortCardBoundary(theRect);
}
tempRect.top = theRect.top + 3;
tempRect.left = theRect.left + 3;
tempRect.bottom = tempRect.top + 16;
tempRect.right = tempRect.left + 12;
theIcon = theApp->suitPats[whichCard->suit][0];
PlotCIcon(&tempRect,theIcon);
saveFont = qd.thePort->txFont;
saveSize = qd.thePort->txSize;
cardString[0] = 1;
switch(whichCard->card)
{
case 1:
cardString[1] = 'A';
break;
case 11:
cardString[1] = 'J';
break;
case 12:
cardString[1] = 'Q';
break;
case 13:
cardString[1] = 'K';
break;
default:
NumToString((long)whichCard->card, cardString);
}
TextSize(12);
TextFont(systemFont);
tempRect.left += 14;
MoveTo(tempRect.left, tempRect.bottom -4);
DrawString(cardString);
if (fullCard)
{
TextSize(24);
tempRect.left = theRect.left + ((theRect.right - theRect.left)/2);
tempRect.top = theRect.top + ((theRect.bottom - theRect.top)/2) + 6;
tempRect.left -= StringWidth(cardString)/2;
MoveTo(tempRect.left, tempRect.top);
DrawString(cardString);
tempRect.top = theRect.bottom - 19;
tempRect.left = theRect.right - 15;
tempRect.bottom = tempRect.top + 16;
tempRect.right = tempRect.left + 12;
theIcon = theApp->suitPats[whichCard->suit][1];
PlotCIcon(&tempRect,theIcon);
}
// restore everything
TextSize(saveSize);
TextFont(saveFont);
RGBBackColor(&theBackColor);
}
short CardDeck::GetNextCardPosition(void)
{
nextCardPosition++;
if (nextCardPosition >= NumCards)
return (kNoCard);
return ((short)nextCardPosition);
}
short CardDeck::GetPositionValue(short whichPosition)
{
return ((short)theCardPositions[whichPosition]);
}
void CardDeck::GetCardInfo(short whichCard, CardStruct *cardInfo)
{
if ((whichCard == kNoCard) || (whichCard < 0) || (whichCard > NumCards))
{
cardInfo->card = kNoCard;
return;
}
cardInfo->suit = whichCard / 13;
cardInfo->card = (whichCard % 13) + 1;
if ((cardInfo->suit == 0) || (cardInfo->suit == 3))
cardInfo->color = blackCard;
else
cardInfo->color = redCard;
}
void CardDeck::DrawShortCardBoundary(Rect theRect)
{
Rect tempRect = theRect;
RgnHandle newRgn, oldRgn;
oldRgn = NewRgn();
OpenRgn();
tempRect.bottom +=20;
FrameRoundRect(&tempRect, 20, 20);
CloseRgn(oldRgn);
newRgn = NewRgn();
OpenRgn();
tempRect.bottom += 22;
tempRect.top += 22;
FrameRoundRect(&tempRect, 20, 20);
CloseRgn(newRgn);
// DiffRgn(newRgn,oldRgn,newRgn);
DiffRgn(oldRgn, newRgn, newRgn);
// RectRgn(oldRgn,&theRect);
// SectRgn(newRgn,oldRgn,newRgn);
// saveClipRgn = NewRgn();
// GetClip(saveClipRgn);
// SetClip(newRgn);
EraseRgn(newRgn);
FrameRgn(newRgn);
}